import BaseUtil from '@/BaseUtil';
import SelectUtil from '@/SelectUtil';
import EffectCommon from 'code/Core/Common/EffectCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import TalentBase from 'code/Scripts/Abilities/base/TalentBase';
const desc = `每当杀死一个单位，在其尸体内注入瘟疫，持续对周围的敌人造成${ColorSafe}法强x0.65|r的毒性伤害，持续${ColorSafe}10|r秒。|n觉醒效果：当施放技能时也会在原地留下一团瘟疫。`;
const art = 'ReplaceableTextures\\CommandButtons\\BTNPlagueCloud.blp';
const name = '瘟疫传播';
const config: TalentConfigModel = {
    id: 'talent_t_TalentTransferPlague',
    name,
    desc,
    art,
    buffType: {
        id: 'buff_t_TalentTransferPlague',
        art,
        name,
        ubertip: desc,
    },
    buffTypePlus: {
        id: 'buff_t_TalentTransferPlague_plus',
        art,
        name: '瘟疫传播[觉醒]',
        ubertip: `每当杀死一个单位，在其尸体内注入瘟疫，持续对周围的敌人造成${ColorSafe}法强x0.65|r的毒性伤害，持续${ColorSafe}10|r秒，且在施放技能时也会在原地留下一团瘟疫`,
    },
};
export default class TalentTransferPlague extends TalentBase {
    static instance: TalentTransferPlague;
    constructor(p?: TalentConfigModel) {
        super(p);
        TalentTransferPlague.instance = this;
        this.setTalentConfig(config);
        EventManager.单位死亡(this.deathEffect);
        se.onUnitSpellEffect(this.spellEffect);
    }
    spellEffect() {
        let u = GetTriggerUnit();
        let _this = TalentTransferPlague.instance;
        let { unEffect, plus } = _this.talentUnEffect(u);
        if (!plus) return;
        _this.castPlague(GetUnitX(u), GetUnitY(u), u);
    }
    castPlague(tarX: number, tarY: number, source: unit) {
        EffectCommon.addEffectAndDeleyRemove('SpiderToxin.mdx', tarX, tarY, 10);
        BaseUtil.onTimer(1, (c) => {
            let dmg = UnitCommon.取法强(source) * 0.65;
            let es = SelectUtil.getEnemyUnitsInRange(source, 155, tarX, tarY);
            if (es.length > 0) DamageSystemInstance.applyAoeMagicDamage(es, source, dmg, 'poision');
            return c < 10;
        });
    }
    // 敌方死亡里释放瘟疫
    deathEffect(d: DamageEventData) {
        let _this = TalentTransferPlague.instance;
        let { unEffect, plus } = _this.talentUnEffect(d.source);
        if (unEffect) return;
        _this.castPlague(GetUnitX(d.target), GetUnitY(d.target), d.source);
    }
}
